package com.learn.demo.advice;

import com.dtflys.forest.exceptions.ForestRuntimeException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author banjiawei
 * @date 2020/08/24
 * 全局异常处理类
 */
//@RestControllerAdvice
@Slf4j
public class ForestRuntimeExceptionAdvice {

    @ExceptionHandler(ForestRuntimeException.class)
    public String ForestRuntimeExceptionHandler(ForestRuntimeException e) {
        String message = e.getMessage();
        log.info("{}", message);
        // 然后提取错误提示信息进行返回
        return e.getMessage();
    }

    @ExceptionHandler(Exception.class)
    public String ExceptionHandler(Exception e){
        String message = e.getMessage();
        log.info("{}", message);
        // 然后提取错误提示信息进行返回
        return e.getMessage();
    }
}
